Skip to main content

Backup WiFi Connections

Description

The back_up_connections function backs up all existing Wi-Fi connections to a specified JSON file.

Function Signature:

def back_up_connections(backup_file_path: str) -> None:

Parameters

  • backup_file_path: The file path where the backup will be stored.

Returns

  • None

Example Usage

back_up_connections('/path/to/backup.json')

Notes

This function uses nmcli to export the current Wi-Fi connections in JSON format, and then writes the resulting data to a file. If the operation is successful, a message is printed indicating the file path where the connections were backed up.

  • The subprocess.run() method is used to execute nmcli commands, which are part of NetworkManager.
  • If an error occurs during the backup process (e.g., if nmcli fails or if there's an issue with file permissions), the error message will be printed.

Error Handling

  • If the nmcli command fails (e.g., due to incorrect input or missing permissions), a subprocess.CalledProcessError will be caught and the error message will be printed.